package com.hong.controller;


import com.hong.config.TopicConfig;
import com.hong.dto.UserDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URL;
import java.util.List;

@Api(value ="用户信息",tags = {"用户信息"})
@RequestMapping("user")
@RestController
public class UserController {

    private Logger logger = LoggerFactory.getLogger(UserController.class);


    @Autowired
    private RedisTemplate redisTemplate;


    @ApiOperation(value = "更新用户",tags = {"用户信息"})
    @PutMapping("update")
    public Boolean update(@RequestBody UserDTO param){
        redisTemplate.convertAndSend(TopicConfig.ASYNC_CALL_TOPIC,"first message!!!");
        logger.info("name:{},code:{}",param.getName(),param.getCode());
        return true;
    }

    @ApiOperation(value = "上传文档",tags = {"用户信息"})
    @PostMapping("upload")
    public Boolean upload(@RequestPart("files") List<MultipartFile> files) throws IOException {
//        String name = file.getName();
//        byte[] bytes = file.getBytes();
//        Resource resource = file.getResource();
////        InputStream inputStream = file.getInputStream();
//        long size = file.getSize();
//        String contentType = file.getContentType();
//        String filename = resource.getFilename();
////        InputStream inputStream1 = resource.getInputStream();
////        URI uri = resource.getURI();
////        URL url = resource.getURL();
////        File file1 = resource.getFile();
//        logger.info("file:{}",file.getOriginalFilename());
        for (MultipartFile multipartFile : files) {
            logger.info("file:{}",multipartFile.getOriginalFilename());
        }
        return true;
    }


}
